package com.yuyou.tas.feedback.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yuyou.tas.service.api.feedback.dto.FeedbackListDTO;
import com.yuyou.tas.service.api.feedback.service.FeedbackAPI;
import com.yuyou.tas.util.bean.PageParams;
import com.yuyou.tas.util.bean.Pagination;
import com.yuyou.tas.util.bean.ReturnResult;
import com.yuyou.tas.util.enums.feedback.FeedbackEnums;

/**
 * Created by yujin.liu on 2019/1/23.
 */
@Api(value="FeedbackController",description="PC端反馈接口")
@Validated
@RestController
@RequestMapping(value = "/api/feedback")
public class FeedbackController {


    @Autowired
    private FeedbackAPI feedbackAPI;


    @ApiOperation(value = "查询学生反馈列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentId", value = "学生 ID 不能为空", paramType = "query", required = true)
    })
    @RequestMapping(value = "/feedbackList", method = { RequestMethod.POST })
    public ReturnResult<List<FeedbackListDTO>> findFeedList(@NotNull(message = "学生 ID 不能为空") Long studentId,
                                                            @Validated @ModelAttribute PageParams pageParams) throws Exception {


        Map<String, Object> conditions = new HashMap<>();
        Pagination<FeedbackListDTO> queryPgn = new Pagination<>();
        conditions.put("studentId", studentId);
        conditions.put("status", FeedbackEnums.status.published.getValue());
        queryPgn.setConditions(conditions);
        queryPgn.setPageParams(pageParams);

        int total = feedbackAPI.findFeedbackCount(queryPgn);
        queryPgn.setTotal(total);
        queryPgn.toBePage();
        if(total > 0){
            List<FeedbackListDTO> list = feedbackAPI.feedbackList(queryPgn);
            queryPgn.setList(list);
        }

        return ReturnResult.success(queryPgn);
    }



}
